module Sustainalytics.Accounts.Admin {

    import Common = Sustainalytics.Common;
    import CommonAdmin = Sustainalytics.Common.Admin;
    import Routing = Sustainalytics.Routing;

    interface IUserDetailsController extends ng.IScope {
        getUser: any;
        userDetails: UsersDto;
        formatDate: any;
        resetPassword: any;
    }

    class UserDetailsController {

        private $routeParams: any;

        constructor(
            private $scope: IUserDetailsController,
            $rootScope,
            RoutingService: Routing.IRoutingService,
            notificationFactory: Common.INotificationFactory,
            staticObjectsAdmin: CommonAdmin.IStaticObjects,
            userFactory: UsersService) {

            var ctx = this;

            ctx.$routeParams = RoutingService.getRouteParams();

            var userId = ctx.$routeParams.userId;

            $scope.getUser = () => {
                userFactory.userGet(userId)
                    .then(user => {

                   // user.passwordExpirationDate = new Date(user.passwordExpirationDate.toString());
                        $scope.userDetails = user;
                        //$scope.userDetails = user;
                        // $scope.userDetails.passwordExpirationDate = new Date(user.passwordExpirationDate.toString());
                    });
            };

            $scope.resetPassword = () => {
                var listOfIds = [$scope.userDetails.id.toString()];
                if (confirm("The password will be reset for this user."
                    + "\n" + "Are you sure that you want to continue?")
                    ) {
                    userFactory.usersResetPasswords(listOfIds)
                        .then(result=> {
                        notificationFactory.success("The password has been reset for 1 user.");
                    });
                }
            }

            $.when($scope.getUser());
        }
    }


    var mod = angular.module(accountAdminModuleName);

    mod.controller('UserDetailsController',
        ['$scope', '$rootScope', 'RoutingService', 'notificationFactory', 'staticObjectsAdmin', 'UsersService', UserDetailsController]);
}